package jnpf.service.impl;

import jnpf.entity.ZXGL_ZhiDingDuBanRenEntity;
import jnpf.mapper.ZXGL_ZhiDingDuBanRenMapper;
import jnpf.service.ZXGL_ZhiDingDuBanRenService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import jnpf.util.RandomUtil;
import java.math.BigDecimal;


import jnpf.model.zxgl_zhidingdubanren.ZXGL_ZhiDingDuBanRenPagination;
import cn.hutool.core.util.ObjectUtil;
import jnpf.permission.service.AuthorizeService;
import java.lang.reflect.Field;
import com.baomidou.mybatisplus.annotation.TableField;
import java.util.stream.Collectors;





import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import java.text.SimpleDateFormat;
import jnpf.util.*;
import java.util.*;

/**
 *
 * ZXGL_ZhiDingDuBanRen
 * 版本： V2.0
 * 版权： 河北交投智能交通技术有限责任公司
 * 作者： 数字交投项目组
 * 日期： 2025-03-08
 */
@Service
public class ZXGL_ZhiDingDuBanRenServiceImpl extends ServiceImpl<ZXGL_ZhiDingDuBanRenMapper, ZXGL_ZhiDingDuBanRenEntity> implements ZXGL_ZhiDingDuBanRenService{


    @Autowired
    private UserProvider userProvider;

    @Autowired
    private AuthorizeService authorizeService;





    @Override
    public List<ZXGL_ZhiDingDuBanRenEntity> getList(ZXGL_ZhiDingDuBanRenPagination zXGL_ZhiDingDuBanRenPagination){
        String userId=userProvider.get().getUserId();
        List<String> AllIdList =new ArrayList();
        int total=0;
                    QueryWrapper<ZXGL_ZhiDingDuBanRenEntity> zXGL_ZhiDingDuBanRenQueryWrapper=new QueryWrapper<>();
            int zXGL_ZhiDingDuBanRenNum =0;
			if(StringUtil.isNotEmpty(zXGL_ZhiDingDuBanRenPagination.getDbxm())){
            zXGL_ZhiDingDuBanRenNum++;
            zXGL_ZhiDingDuBanRenQueryWrapper.lambda().like(ZXGL_ZhiDingDuBanRenEntity::getDbxm,zXGL_ZhiDingDuBanRenPagination.getDbxm());
                    }

			if(StringUtil.isNotEmpty(zXGL_ZhiDingDuBanRenPagination.getDbrw())){
            zXGL_ZhiDingDuBanRenNum++;
            zXGL_ZhiDingDuBanRenQueryWrapper.lambda().like(ZXGL_ZhiDingDuBanRenEntity::getDbrw,zXGL_ZhiDingDuBanRenPagination.getDbrw());
                    }

			if(StringUtil.isNotEmpty(zXGL_ZhiDingDuBanRenPagination.getDbr())){
            zXGL_ZhiDingDuBanRenNum++;
                zXGL_ZhiDingDuBanRenQueryWrapper.lambda().eq(ZXGL_ZhiDingDuBanRenEntity::getDbr,zXGL_ZhiDingDuBanRenPagination.getDbr());
                    }

        if(AllIdList.size()>0){
            zXGL_ZhiDingDuBanRenQueryWrapper.lambda().in(ZXGL_ZhiDingDuBanRenEntity::getId, AllIdList);
        }
    /**
    * 数据权限 此处手动写入菜单id
    */
//    String moduleId = "";
//    if (!userProvider.get().getIsAdministrator()){
//    Object conditionObj = authorizeService.getCondition(zXGL_ZhiDingDuBanRenQueryWrapper,userProvider.get(),moduleId);
//        if (ObjectUtil.isEmpty(conditionObj)){
//        return new ArrayList<>();
//        }
//            zXGL_ZhiDingDuBanRenQueryWrapper=(QueryWrapper<ZXGL_ZhiDingDuBanRenEntity>)authorizeService.getCondition( zXGL_ZhiDingDuBanRenQueryWrapper,userProvider.get(),moduleId);
//        }
        //排序
        if(StringUtil.isEmpty(zXGL_ZhiDingDuBanRenPagination.getSidx())){
        zXGL_ZhiDingDuBanRenQueryWrapper.lambda().orderByDesc(ZXGL_ZhiDingDuBanRenEntity::getDbxm);
        }else{
            try {
                String sidx = zXGL_ZhiDingDuBanRenPagination.getSidx();
                ZXGL_ZhiDingDuBanRenEntity zXGL_ZhiDingDuBanRenEntity = new ZXGL_ZhiDingDuBanRenEntity();
                Field declaredField = zXGL_ZhiDingDuBanRenEntity.getClass().getDeclaredField(sidx);
                declaredField.setAccessible(true);
                String value = declaredField.getAnnotation(TableField.class).value();
                zXGL_ZhiDingDuBanRenQueryWrapper="asc".equals(zXGL_ZhiDingDuBanRenPagination.getSort().toLowerCase())?zXGL_ZhiDingDuBanRenQueryWrapper.orderByAsc(value):zXGL_ZhiDingDuBanRenQueryWrapper.orderByDesc(value);
            } catch (NoSuchFieldException e) {
                e.printStackTrace();
            }
        }
        if((total>0 && AllIdList.size()>0) || total==0){
        Page<ZXGL_ZhiDingDuBanRenEntity> page=new Page<>(zXGL_ZhiDingDuBanRenPagination.getCurrentPage(), zXGL_ZhiDingDuBanRenPagination.getPageSize());
        IPage<ZXGL_ZhiDingDuBanRenEntity> userIPage=this.page(page, zXGL_ZhiDingDuBanRenQueryWrapper);
        return zXGL_ZhiDingDuBanRenPagination.setData(userIPage.getRecords(),userIPage.getTotal());
        }else{
            List<ZXGL_ZhiDingDuBanRenEntity> list = new ArrayList();
            return zXGL_ZhiDingDuBanRenPagination.setData(list, list.size());
        }
    }
    @Override
    public List<ZXGL_ZhiDingDuBanRenEntity> getTypeList(ZXGL_ZhiDingDuBanRenPagination zXGL_ZhiDingDuBanRenPagination,String dataType){
        String userId=userProvider.get().getUserId();
        List<String> AllIdList =new ArrayList();
		int total=0;
                    QueryWrapper<ZXGL_ZhiDingDuBanRenEntity> zXGL_ZhiDingDuBanRenQueryWrapper=new QueryWrapper<>();
            int zXGL_ZhiDingDuBanRenNum =0;
			if(StringUtil.isNotEmpty(zXGL_ZhiDingDuBanRenPagination.getDbxm())){
            zXGL_ZhiDingDuBanRenNum++;
            zXGL_ZhiDingDuBanRenQueryWrapper.lambda().like(ZXGL_ZhiDingDuBanRenEntity::getDbxm,zXGL_ZhiDingDuBanRenPagination.getDbxm());
                    }

			if(StringUtil.isNotEmpty(zXGL_ZhiDingDuBanRenPagination.getDbrw())){
            zXGL_ZhiDingDuBanRenNum++;
            zXGL_ZhiDingDuBanRenQueryWrapper.lambda().like(ZXGL_ZhiDingDuBanRenEntity::getDbrw,zXGL_ZhiDingDuBanRenPagination.getDbrw());
                    }

			if(StringUtil.isNotEmpty(zXGL_ZhiDingDuBanRenPagination.getDbr())){
            zXGL_ZhiDingDuBanRenNum++;
                zXGL_ZhiDingDuBanRenQueryWrapper.lambda().eq(ZXGL_ZhiDingDuBanRenEntity::getDbr,zXGL_ZhiDingDuBanRenPagination.getDbr());
                    }

    /**
    * 数据权限 此处手动写入菜单id
    */
//    String moduleId = "";
//    if (!userProvider.get().getIsAdministrator()){
//    Object conditionObj = authorizeService.getCondition(zXGL_ZhiDingDuBanRenQueryWrapper,userProvider.get(),moduleId);
//        if (ObjectUtil.isEmpty(conditionObj)){
//        return new ArrayList<>();
//        }
//            zXGL_ZhiDingDuBanRenQueryWrapper=(QueryWrapper<ZXGL_ZhiDingDuBanRenEntity>)authorizeService.getCondition(zXGL_ZhiDingDuBanRenQueryWrapper,userProvider.get(),moduleId);
//            }
//		if(AllIdList.size()>0){
//        zXGL_ZhiDingDuBanRenQueryWrapper.lambda().in(ZXGL_ZhiDingDuBanRenEntity::getId, AllIdList);
//				}
        //排序
        if(StringUtil.isEmpty(zXGL_ZhiDingDuBanRenPagination.getSidx())){
        zXGL_ZhiDingDuBanRenQueryWrapper.lambda().orderByDesc(ZXGL_ZhiDingDuBanRenEntity::getDbxm);
        }else{
            try {
            	String sidx = zXGL_ZhiDingDuBanRenPagination.getSidx();
                ZXGL_ZhiDingDuBanRenEntity zXGL_ZhiDingDuBanRenEntity = new ZXGL_ZhiDingDuBanRenEntity();
				Field declaredField = zXGL_ZhiDingDuBanRenEntity.getClass().getDeclaredField(sidx);
				declaredField.setAccessible(true);
				String value = declaredField.getAnnotation(TableField.class).value();
                 zXGL_ZhiDingDuBanRenQueryWrapper="asc".equals(zXGL_ZhiDingDuBanRenPagination.getSort().toLowerCase())?zXGL_ZhiDingDuBanRenQueryWrapper.orderByAsc(value):zXGL_ZhiDingDuBanRenQueryWrapper.orderByDesc(value);
            } catch (NoSuchFieldException e) {
                e.printStackTrace();
            }
        }
        if("0".equals(dataType)){
            if((total>0 && AllIdList.size()>0) || total==0){
                Page<ZXGL_ZhiDingDuBanRenEntity> page=new Page<>(zXGL_ZhiDingDuBanRenPagination.getCurrentPage(), zXGL_ZhiDingDuBanRenPagination.getPageSize());
                IPage<ZXGL_ZhiDingDuBanRenEntity> userIPage=this.page(page, zXGL_ZhiDingDuBanRenQueryWrapper);
                return zXGL_ZhiDingDuBanRenPagination.setData(userIPage.getRecords(),userIPage.getTotal());
            }else{
                List<ZXGL_ZhiDingDuBanRenEntity> list = new ArrayList();
                return zXGL_ZhiDingDuBanRenPagination.setData(list, list.size());
            }
        }else{
            return this.list(zXGL_ZhiDingDuBanRenQueryWrapper);
        }
    }

    @Override
    public ZXGL_ZhiDingDuBanRenEntity getInfo(String id){
        QueryWrapper<ZXGL_ZhiDingDuBanRenEntity> queryWrapper=new QueryWrapper<>();
        queryWrapper.lambda().eq(ZXGL_ZhiDingDuBanRenEntity::getId,id);
        return this.getOne(queryWrapper);
    }

    @Override
    public void create(ZXGL_ZhiDingDuBanRenEntity entity){
        this.save(entity);
    }

    @Override
    public boolean update(String id, ZXGL_ZhiDingDuBanRenEntity entity){
        entity.setId(id);
        return this.updateById(entity);
    }
    @Override
    public void delete(ZXGL_ZhiDingDuBanRenEntity entity){
        if(entity!=null){
            this.removeById(entity.getId());
        }
    }
    //子表方法

    //列表子表数据方法


}